{block name="main"}

<ul id="bargain_type" class="nav nav-tabs v-nav-tabs fs-12">
    <li role="presentation" class="active" data-type="payed"><a href="javascript:void(0)" data-toggle="tab" class="flex-auto-center" aria-expanded="true">已支付<span class="J-all">({$bargain_status_arr['pay_count']})</span></a></li>
    <li role="presentation" class="" data-type="going"><a href="javascript:void(0)" data-toggle="tab" class="flex-auto-center" aria-expanded="false">砍价中<span class="J-all">({$bargain_status_arr['going_count']})</span></a></li>
    <li role="presentation" class="" data-type="fail"><a href="javascript:void(0)" data-toggle="tab" class="flex-auto-center" aria-expanded="false">砍价失败<span class="J-all">({$bargain_status_arr['fail_count']})</span></a></li>
    <input type="hidden" id="bargain_status" name="bargain_status" value="payed">
    <div class="input-group search-input-group ml-10" style="float:right;position: relative">
        <div class="date-input-control" style="margin-top: 3px">
            <input type="text" class="form-control" id="date" placeholder="查询时间"><i class="icon icon-calendar" style="z-index: 55"></i>
            <input type="hidden" id="bargain_time" name="bargain_time" value="">
        </div>
        <span class="input-group-btn">
            <button class="btn btn-primary search" type="button">搜索</button>
        </span>
    </div>
</ul>
<table class="table v-table table-auto-center">
    <thead>
    <tr>
        <th>会员</th>
        <th>已砍/原价</th>
        <th>帮砍人数</th>
        <th>现价</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="group_shopping_list">
    </tbody>
</table>
<input type="hidden" id="page_index">
<nav aria-label="Page navigation" class="clearfix">
    <ul id="page" class="pagination pull-right"></ul>
</nav>
{/block}
{block name="script"}
<script id="shop_curr_list" type="text/html">
    <%each data as item index%>
    <tr>
        <td>
            <div class="media text-left ">
                <div class="media-left">
                    <p><img src="<%item.pic_cover%>" style="width:60px;height:60px;"></p>
                </div>
                <div class="media-body max-w-300 ">
                    <div class="line-2-ellipsis line-title">
                        <%item.user_name%>
                    </div>
                    <div class="line-1-ellipsis text-danger strong"><%item.level_name%></div>
                </div>
            </div>
        </td>

        <td>
            <%item.already_bargain_money%>/<%item.start_price%>
        </td>
        <td>
            <%item.help_count%>
        </td>
        <td><%item.now_bargain_money%></td>
        <td>
            <%if item.bargain_status==1%>
                <a href="javascript:;" class="label label-warning" data-type=1 >砍价中</a>
            <%/if%>
            <%if item.bargain_status==2%>
                <a href="javascript:;" class="label label-success" data-type=1 >已支付</a>
            <%/if%>
            <%if item.bargain_status==3%>
                <a href="javascript:;" class="label label-danger" data-type=1 >砍价失败</a>
            <%/if%>
        </td>
        <td>
            <%if item.order_id!=0%>
            <a href="PLATFORM_MAIN/order/orderdetail?order_id=<%item.order_id%>" class="text-primary block" data-type="history" data-group_id="<%item.order_id%>">查看订单</a>
            <%/if%>
        </td>
    </tr>
    <%/each%>
</script>
<script>
    require(['util', 'tpl'], function (util, tpl) {
        util.layDate("#start_bargain_time");
        util.layDate("#end_bargain_time");
        util.layDate('#date',true,function(value, date, endDate){
            $('#bargain_time').val(value);
            LoadingInfo($('#page_index').val());
        });
        util.initPage(LoadingInfo);
        $('.search').click(function(){
            LoadingInfo($('#page_index').val());
        })
        $('#bargain_type li').click(function(){
            $(this).addClass('active').siblings().removeClass('active');
            $('#bargain_status').val($(this).data('type'));
            LoadingInfo($('#page_index').val());
        })
        function LoadingInfo(page_index) {
            $("#page_index").val(page_index);
            var bargain_id = '{$bargain_id}';
            var bargain_status = $('#bargain_status').val();
            var bargain_time = $('#bargain_time').val();
            $.ajax({
                type: "post",
                url: "{$bargainRecordUrl}",
                data: {
                    "page_index": page_index,
                    "bargain_status": bargain_status,
                    "bargain_time": bargain_time,
                    "bargain_id": bargain_id
                },
                success: function (data) {
                    var html = '<tr><td class="h-200" colspan="6">暂无符合条件的数据记录</td></tr>';
                    if(data.data){
                        if (tpl('shop_curr_list', data)) {
                            for(var i = 0;i < data.data.length; i++){
                                data.data[i]['pic_cover_mid'] = __IMG( data.data[i]['pic_cover']);
                            }
                            $("#group_shopping_list").html(tpl('shop_curr_list', data));
                        } else {
                            $("#group_shopping_list").html(html);
                        }
                        $('#page').paginator('option', {
                            totalCounts: data['total_count']  // 动态修改总数
                        });
                    }else{
                        $("#group_shopping_list").html(html);
                    }
                }
            });
        }







        $('#group_shopping_list').on('click', '.del', function () {
            var group_id = $(this).attr('data-group_id');
            util.alert('删除？', function () {
                $.ajax({
                    type: "post",
                    url: "{$deleteGroupShoppingUrl}",
                    data: {"group_id": group_id},
                    dataType: "json",
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', LoadingInfo($('#page_index').val(),type));
                        } else {
                            util.message(data['message']);
                        }
                    }
                });
            });
        });
        $('#group_shopping_list').on('click', '.off', function () {
            var group_id = $(this).attr('data-group_id');
            util.alert('关闭后未成团的订单将作废处理！', function () {
                $.ajax({
                    type: "post",
                    url: "{$closeGroupShoppingUrl}",
                    data: {"group_id": group_id},
                    dataType: "json",
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', LoadingInfo($('#page_index').val(),type));
                        } else {
                            util.message(data['message']);
                        }
                    }
                });
            });
        });
        $('#group_shopping_list').on('click', '.on', function () {
            var group_id = $(this).attr('data-group_id');
            util.alert('开启活动？', function () {
                $.ajax({
                    type: "post",
                    url: "{$openGroupShoppingUrl}",
                    data: {"group_id": group_id},
                    dataType: "json",
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', LoadingInfo($('#page_index').val(),type));
                        } else {
                            util.message(data['message']);
                        }
                    }
                });
            });
        });
        $('#group_type').on('click','li',function(){
            type = $(this).data('type');
            LoadingInfo(1);
        });
        $('#group_shopping_list').on('click', '.text-primary.block', function () {
            var type = $(this).attr('data-type');
            var group_id = $(this).attr('data-group_id');
            switch (type) {
                case 'edit':
                    location.href = __URL('ADDONS_MAINupdateGroupShopping&group_id=' + group_id);
                    break;
                case 'info':
                    location.href = __URL('ADDONS_MAINgroupShoppingDetail&group_id=' + group_id);
                    break;
                case 'history':
                    location.href = __URL('ADDONS_MAINgroupRecord&group_id=' + group_id);
                    break;
            }
        });
    });


</script>
{/block}